package com.cskaoyan.controller.wxcollect;

import com.cskaoyan.model.bo.wxcollect.AddordeleteBo;
import com.cskaoyan.model.vo.BaseData;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.service.wxcollect.WxCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @program: project-market
 * @description:
 * @author: Weiwei Liu
 * @create: 2021-12-02 22:26
 **/
@RestController
@RequestMapping("wx/collect")
public class WxCollectController {

    @Autowired
    WxCollectService wxCollectService;

    @RequestMapping("list")
    public BaseRespVo list(Integer type, Integer page, Integer limit, HttpSession session) {

        Integer uid = (Integer) session.getAttribute("uid");

        if (uid == null) return BaseRespVo.manual(501, "请登录", null);

        BaseData baseData = wxCollectService.list(uid, type, page, limit);

        return BaseRespVo.ok(baseData);
    }


    /**
     * 收藏或者取消收藏
     *
     * @param bo
     * @return
     */
    @PostMapping("addordelete")
    public BaseRespVo addordelete(@RequestBody AddordeleteBo bo, HttpSession session) {

        Integer uid = (Integer) session.getAttribute("uid");

        if (uid == null) return BaseRespVo.manual(501, "请登录", null);

        Integer i = wxCollectService.addordelete(bo, uid);

        if (i == 1) return BaseRespVo.ok();

        return BaseRespVo.fail("收藏/取消失败");
    }
}
